<template>
  <div>
    <el-table
      :data="tableData"
      border
      style="width: 100%">
      <el-table-column
        fixed
        prop="Contract_id"
        label="合同编号"
        width="80">
      </el-table-column>
      <el-table-column
        prop="Contract_date"
        label="合同日期"
        width="120">
      </el-table-column>
      <el-table-column
        prop="Product_id"
        label="产品代码"
        width="80">
      </el-table-column>
      <el-table-column
        prop="Product_type"
        label="规格型号"
        width="80">
      </el-table-column>
      <el-table-column
        prop="Product_amount"
        label="数量"
        width="80">
      </el-table-column>
      <el-table-column
        prop="Product_price"
        label="单价"
        width="80">
      </el-table-column>
      <el-table-column
        prop="Supplier"
        label="供货单位"
        width="120">
      </el-table-column>
      <el-table-column
        prop="Deliver_date"
        label="供货日期"
        width="120">
      </el-table-column>
      <el-table-column
        prop="Supply_place"
        label="地址"
        width="120">
      </el-table-column>
      <el-table-column
        prop="Supply_phone"
        label="电话"
        width="120">
      </el-table-column>
      <el-table-column
        prop="Supply_way"
        label="供货方式"
        width="120">
      </el-table-column>
      <el-table-column
        prop="Supply_name"
        label="姓名"
        width="120">
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            size="mini"
            @click="handleEdit(scope.row)">编辑</el-button>
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      layout="prev, pager, next"
      page-size="6"
      :total="total"
      @current-change="page">
    </el-pagination>
  </div>
</template>

<script>
export default {
  methods: {
    handleDelete (row) {
      const _this = this
      this.axios.post('http://localhost:8111/delete', { Contract_id: row.Contract_id }).then((resp) => {
        _this.$alert('合同编号为' + row.Contract_id + '删除成功！', '消息', {
          confirmButtonText: '确定',
          callback: action => {
            window.location.reload()
          }
        })
      })
    },
    handleEdit (row) {
      this.$router.push({
        name: 'update',
        path: '/update',
        query: row
      })
    },
    page () {
      const _this = this
      this.axios.post('http://localhost:8111/findall').then((res) => {
        _this.tableData = res.data
        _this.total = res.data
      })
    }
  },
  created () {
    const _this = this
    this.axios.post('http://localhost:8111/findall').then((res) => {
      console.log(res.data)
      _this.tableData = res.data
      // _this.total = res.data.totalElements
    })
  },
  data () {
    return {
      total: null,
      tableData: null
    }
  }
}
</script>
